import config from './config.js'
import store from '@/store/index.js'
import moment from 'moment'

var tempFiles = {};

const getNowDate = (format = "YYYY-MM-DD HH:mm:ss") => {
	return moment().format(format);
}

const getDate = (d, format = 'YYYY-MM-DD') => {
	let dd = moment();
	if (d) {
		dd.add(d, 'days')
	}
	return dd.format('YYYY-MM-DD')
}

const isBefore = (startTime) => {
	let dd = moment();
	return dd.isBefore(startTime)
}

const isAfter = (endTime) => {
	let dd = moment();
	return dd.isAfter(endTime)
}

let systemInfo = null
const getSystemInfo = (key) => {
	if (systemInfo) {
		console.log("systemInfo", JSON.stringify(systemInfo))
		return systemInfo[key]
	}
	systemInfo = uni.getSystemInfoSync()
	console.log("systemInfo", JSON.stringify(systemInfo))
	return systemInfo[key]
}

const formatVersion = (version) => {
	let ver = version.split('.')
	let v = "";
	if (ver[0] < 10) {
		v += ver[0] + "0"
	} else {
		v += ver[0]
	}
	if (ver[1] < 10) {
		v += "0" + ver[1]
	} else {
		v += ver[1]
	}
	if (ver[2] < 10) {
		v += "0" + ver[2]
	} else {
		v += ver[2]
	}
	return v
}


const previewImage = (urls, current) => {
	uni.previewImage({
		urls: urls,
		current: current,
		indicator: "default",
		loop: false,
		longPressActions: false,
		success: () => {

		}
	})
}

const setStorage = (key, data) => {
	if (key && data) {
		if (typeof data === 'string') {
			uni.setStorageSync(key, data)
		} else {
			uni.setStorageSync(key + '_JSON', JSON.stringify(data))
		}
	}
}

const getStorage = (key) => {
	if (key) {
		let value = uni.getStorageSync(key);
		if (!value) {
			value = uni.getStorageSync(key + '_JSON');
			if (value) {
				return JSON.parse(value)
			}
		}
		return value
	}
	return '';
}

const urlParams = (obj) => {
	let paramsStr = '?1=1';
	for (let key in obj) {
		paramsStr = paramsStr + '&' + key + '=' + encodeURIComponent(obj[key])
	}
	return paramsStr
}

const getMedia = (count = 1, soutceType = ['album', 'camera']) => {
	return new Promise((resolve) => {
		uni.chooseMedia({
			count: count,
			sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
			maxDuration: 15,
			sourceType: soutceType, //从相册选择
			success: function(res) {
				resolve(res)
			}
		});
	})
}

const getPhoto = (count = 1, soutceType = ['album', 'camera']) => {
	return new Promise((resolve) => {
		uni.chooseImage({
			count: count,
			sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
			sourceType: soutceType, //从相册选择
			success: function(res) {
				resolve(res)
			}
		});
	})
}


const uploadFile = (filePath, size = '', waterMark = true) => {
	if (filePath) {
		showLoading();
		let formData = {}
		if (size) {
			formData.size = size
		}
		if (waterMark) {
			formData.waterMark = store.state.nickName || ('用户' + store.state.userName.substr(5))
		} else {
			formData.waterMark = 'false'
		}
		return new Promise((resolve) => {
			uni.uploadFile({
				url: '', //config.UPLOAD_URL, //仅为示例，非真实的接口地址
				filePath: filePath,
				name: 'file',
				formData: formData,
				success: (res) => {
					resolve(JSON.parse(res.data))
				},
				complete: () => {
					hideLoading()
				}
			});
		})
	}
}

const alert = ({
	content,
	confirmText
}) => {
	if (content) {
		return new Promise((resolve) => {
			uni.showModal({
				content: content,
				showCancel: false,
				confirmText: confirmText || '确定',
				confirmColor: '#DF0108',
				success: function(res) {
					resolve()
				}
			});
		})
	} else {
		return new Promise((resolve) => {
			resolve()
		})
	}
}

const confirm = ({
	title,
	content,
	confirmText,
	cancelText,
	confirmColor
}) => {
	if (content || title) {
		return new Promise((resolve) => {
			uni.showModal({
				title: title || '',
				content: content,
				showCancel: true,
				cancelText: cancelText || '取消',
				confirmText: confirmText || '确定',
				confirmColor: confirmColor || '#DF0108',
				success: function(res) {
					if (res.confirm) {
						resolve(true)
					} else if (res.cancel) {
						resolve(false)
					}
				}
			});
		})
	} else {
		return new Promise((resolve) => {
			resolve()
		})
	}
}
var showLoadingNum = 0;
const showLoading = (content) => {
	showLoadingNum++;
	if (content) {
		showLoadingNum = 1;
		uni.hideLoading();
	} else if (showLoadingNum > 1) {
		return;
	}
	uni.showLoading({
		title: content || '加载中',
		mask: true
	});
}

const hideLoading = () => {
	showLoadingNum--;
	if (showLoadingNum > 0) return;
	showLoadingNum = 0;

	uni.hideLoading()
}

const toast = (content) => {
	if (content) {
		setTimeout(() => {
			uni.showToast({
				title: content,
				icon: 'none',
				position: 'bottom',
				duration: 3000
			})
		}, 300)
	}
}

const imageToBase64 = (url) => {
	return new Promise((resolve, reject) => {
		// uni.request({
		// 	url: url,
		// 	method: 'GET',
		// 	responseType: 'arrayBuffer',
		// 	success: (res) => {
		// 	  let imgBase64 = uni.arrayBufferToBase64(res.data);
		// 	  resolve(imgBase64);
		// 	},
		// })
		let data = uni.getFileSystemManager().readFileSync(url, "base64")
		resolve(data)
	})
}

//对象判空的方法
const objectIsEmpty = (obj) => {
	for (let key in obj) {
		return false
	}
	return true
}

var isShowTimeOutAlert = false;
const request = ({
	url,
	data = {},
	type,
	isLoading = true,
	toastFlag = true
}, deviceCtrl = 0) => {
	console.log('url', url)
	if (isLoading) {
		showLoading()
	}
	return new Promise((resolve, reject) => {
		//根据serverUrl包含的前缀去设置对应的token
		let serverUrl = config.BASE_URL + url;
		// console.warn("serverUrl: ",serverUrl)
		const typeArr = serverUrl.split('/')
		// console.log('typeArr',typeArr);
		// console.log('serverUrl22222222222',typeArr.includes('app'))
		let loginInfo = getStorage("loginInfo")
		console.log('loginInfo',loginInfo);
		// if (loginInfo && loginInfo.token) {
		// 	if (serverUrl.indexOf("?") < 0) {
		// 		serverUrl += "?token="+loginInfo.token
		// 	} else {
		// 		serverUrl += "&token="+loginInfo.token
		// 	}
		// }
		if (loginInfo && !objectIsEmpty(loginInfo)) {
			// console.warn("loginInfo: ",serverUrl)
			// console.log('看看有没有vx',serverUrl,loginInfo)
			if (typeArr.includes('app')) {
				serverUrl += "?token=" + loginInfo?.app?.token
			} else {
				// console.log('我进来了vx',loginInfo)
				serverUrl += "?token=" + loginInfo?.wx?.wxToken
			}
		}
		// console.log('12121',serverUrl);
		if (deviceCtrl != 0) {
			// console.log('0000000')
			serverUrl = url
		}
		// console.warn("请求开始: " + serverUrl, ";data:" + JSON.stringify(data));
		uni.request({
			url: serverUrl, //仅为示例，并非真实接口地址。
			data: data,
			method: type || 'POST',
			header: {
				'content-type': 'application/json',
				// "X-Access-Token": store.state.token || uni.getStorageSync("AUTH_TOKEN")
			},
			success: (res) => {
				console.log(res)
				if (res.statusCode == 200) {
					hideLoading()
					if (res.data.errors &&
						res.data.errors.length > 0) { // 接口请求失败
						console.warn("请求失败：", res)
						if (toastFlag) {
							const errors = res.data.errors[0].message.split(':')
							if(errors[1]) toast(errors[1])
							else toast(errors[0])
						}
						reject()
					} else { // 接口请求成功
						// console.warn("请求成功：", res)
						if (res.data.code == "NO_SESSION") {
							if (!isShowTimeOutAlert) {
								isShowTimeOutAlert = true
								alert({
									content: res.data.message || "会话超时，请重新登录",
									confirmText: "确定"
								}).then(() => {
									isShowTimeOutAlert = false
									logout()
								});
							}


							reject()
							return;
						}
						if (res.data.code == "SYSTEM_ERROR" ||
							res.data.code == "CUSTOMIZE_ERROR" ||
							res.data.code == "UNAUTHORIZED_ACCESS") {
							if (toastFlag) toast(res.data.message)
							reject(res.data)
							return;
						}
						if (res.data.result) {
							resolve(res.data.result)
						} else if (res.data.data) {
							resolve(res.data.data)
						} else {
							resolve(res.data)
						}
					}
				} else {
					console.warn("请求失败：", res)
					if (toastFlag) {
						toast(res.data.message)
					}
					reject()
				}
			},
			fail: (err) => {
				console.warn("error=====");
				toast('网络请求失败')
				reject(err)
			},
			complete: () => {
				if (isLoading) {
					hideLoading()
				}
			}
		});
	})
}

const formatGraphqlQuery = (query) => {
	// console.log('query2222',query)
	if (query) {
		let queryParam = "{"
		for (let item of query) {
			queryParam += item.fun
			if (item.params && Object.keys(item.params).length > 0) {
				queryParam += "("
				for (let paramKey in item.params) {
					if (typeof item.params[paramKey] == 'string') {
						if (item.params[paramKey].indexOf("_nostr") >= 0) {
							queryParam += paramKey + ":" + item.params[paramKey].split("_nostr")[0] + ","
						} else {
							queryParam += paramKey + ":\"" + item.params[paramKey] + "\","
						}
					} else {
						console.log('paramKey:', paramKey)
						queryParam += paramKey + ":" + item.params[paramKey] + ","
					}
				}
				queryParam = queryParam.substring(0, queryParam.length - 1)
				queryParam += ")"
			}
			if (item.result) {
				queryParam += "{" + item.result + "}"
			}
		}
		// queryParam = queryParam.slice(0, -1)//去掉最后的逗号
		queryParam += "}"
		return queryParam;
	} else {
		return "{}"
	}
}
const FEEDBACKTYPE = {};
const initFeedbackType = () => {
	return new Promise((resolve, reject) => {
		// console.log('FEEDBACKTYPE',FEEDBACKTYPE, Object.keys(FEEDBACKTYPE).length )
		if (Object.keys(FEEDBACKTYPE).length > 0) {
			resolve(FEEDBACKTYPE)
			return
		}
		let query = formatGraphqlQuery([{
			fun: 'fbTypeList:baseData_getToolDataList', // 海报列表
			params: {
				code: 'PM_FEEDBACK_FBTYPE_nostr'
			},
			result: "data_text, data_value"
		}])
		postGraphql({
			query
		}).then((res) => {
			for (let item of res.fbTypeList) {
				FEEDBACKTYPE[item.data_value] = item.data_text
			}
			resolve(FEEDBACKTYPE)
		})
	})
}

const get = (options) => {
	options.type = 'GET';
	return request(options)
}

const post = (options, deviceCtrl) => {
	options.type = 'POST';
	let ctrUrl = deviceCtrl
	// options.type = 'GET';
	return request(options, ctrUrl)
}

// const postGraphql = (options) => {
// 	options.type = 'POST';
// 	// options.type = 'GET';
// 	return requestGraphql(options)
// }

const postGraphql = ({
	query,
	variables = {},
	operationName = ""
}, options = {}, typeurl = 'wx') => {
	let loginInfo = getStorage("loginInfo")
	let isPermissions = getStorage('isPermissions')
	console.log('isPermissions', isPermissions)
	// if (loginInfo && loginInfo.userType === "TENANT") {
	// 	typeurl='wx'
	// }else if(loginInfo && loginInfo.userType === "NOT_YET_TENANT"){
	// 	typeurl='wx'
	// }else if(loginInfo && loginInfo.userType === "UNBIND_CUSTOMER"){
	// 	typeurl='wx'
	// }else{
	// 	typeurl='app'
	// }
	// switch (loginInfo?.userType) {
	//   case "TENANT":
	//   case "NOT_YET_TENANT":
	//   case "UNBIND_CUSTOMER":
	//     typeurl = 'wx';
	//     break;
	//   default:
	//     typeurl = 'app';
	//     break;
	// }
	// console.log(2222222222,loginInfo);
	if (loginInfo.app) {
		typeurl = 'app'
	} else {
		typeurl = 'wx'
	}
	let prefixType = isPermissions == '' ? typeurl : isPermissions
	/**
	 * 当能获取到isPermissions时改去改变typeurl
	 */
	// if (isPermissions !== '') {
	// 	typeurl = isPermissions
	// }
	// console.log('typeurl',typeurl)
	options = {
		url: prefixType + "/graphql",
		data: {
			query: query,
			operationName: operationName,
			variables: variables
		},
		...options
	};

	options.type = 'POST';
	// options.type = 'GET';
	return request(options)
}

const getImageUrl = () => {
	return config.IMAGE_URL;
}

const goHome = () => {
	let routes = getCurrentPages();
	uni.navigateBack({
		delta: routes.length - 1
	});
};

// 获取元素的信息
const getElementInfo = (el) => {
	return new Promise((resolve, reject) => {
		uni.createSelectorQuery().select(el).fields({
			size: true,
			scrollOffset: true
		}, (data) => {
			resolve(data);
		}).exec();

	})
}

const checkBind = () => {
	return new Promise((resolve, reject) => {
		if (store.state.hasBind) {
			resolve()
		} else {
			confirm({
				title: '提示',
				content: '请先绑定用户信息',
				confirmText: '立即前往'
			}).then((flag) => {
				if (flag) {
					uni.navigateTo({
						url: '/pages/bind/bind'
					})
				}
			})
			reject()
		}
	})
}

const noOpen = () => {
	toast("该功能暂未开放，敬请期待...")
}

const getHeightWithTopEl = (topElName, target) => {
	return new Promise((resolve, reject) => {
		setTimeout(() => {
			uni.getSystemInfo({
				success: (res) => {
					// #ifdef APP-VUE || MP-WEIXIN
					let query = uni.createSelectorQuery();
					if (target) {
						query.in(target)
					}
					if (topElName)
						query.select(topElName).boundingClientRect((boundRes) => {
							console.warn("boundRes: ", boundRes)
							resolve(res.windowHeight - boundRes.bottom)
						}).exec()
					else
						resolve(res.windowHeight)
					return;
					// #endif

					// #ifdef H5
					let bottom = 0;
					if (topElName)
						bottom = document.querySelector(topElName)
						.getBoundingClientRect().bottom
					resolve(res.screenHeight - bottom)
					// #endif

				}
			});
		}, 500)
	});
}
const removeStorage = (key) => {
	uni.removeStorageSync(key)
	uni.removeStorageSync(key + '_JSON')
}

const getElRect = (elName, target) => {
	return new Promise((resolve, reject) => {
		setTimeout(() => {
			uni.getSystemInfo({
				success: (res) => {
					// #ifdef APP-VUE || MP-WEIXIN
					let query = uni.createSelectorQuery();
					if (target) {
						query.in(target)
					}
					if (elName)
						query.select(elName).boundingClientRect((boundRes) => {
							resolve(boundRes)
						}).exec()
					return;
					// #endif

					// #ifdef H5
					if (elName) {
						let rect = document.querySelector(elName)
						.getBoundingClientRect()
						resolve(rect)
					}
					// #endif

				}
			});
		}, 500)
	});
}

const loginSuccess = (loginInfo) => {
	//获取数据没拿到
	console.warn("登录成功信息: ", loginInfo.app);
	// userType: VISITOR 访客；UNBIND_CUSTOMER 未绑定公司的新用户；NOT_YET_TENANT 已绑定公司但不是租户；TENANT 租户
	// loginInfo.userType = "UNBIND_CUSTOMER"
	setStorage("loginInfo", loginInfo)
	reLaunchHomePage()
	changeMenuTwo()
	// if (loginInfo && loginInfo.userType == "UNBIND_CUSTOMER") {	// 未绑定公司的新用户(此状态用户必须进入注册页面，其他页面不可进入)
	// 	uni.navigateTo({
	// 		url: "/pagesC/login/bind-compay?loginInfo="+JSON.stringify(loginInfo)
	// 	})
	// } else {
	// 	setStorage("loginInfo", loginInfo)
	// 	reLaunchHomePage()
	// 	changeMenuTwo()
	// }
}

const logout = () => {
	setStorage("login", {})
	setStorage("loginInfo", {})
	reLaunchHomePage()
	removeStorage('isPermissions')
}

const reLaunchHomePage = (loginInfo) => {
	if (loginInfo) setStorage("loginInfo", loginInfo)

	uni.reLaunch({
		url: "/pages/home/tabbar"
	})
}

const getRights = () => {
	if (isLogin()) {
		let loginInfo = getStorage("loginInfo").app
		return loginInfo.rights;
	}
	return {}
}

const isLogin = () => {
	let loginInfo = getStorage("loginInfo")
	if (loginInfo && (loginInfo?.app?.token || loginInfo?.wx?.wxToken)) {
		return true
	}
	return false
}

/**
 * 检查是不是为租户
 */
const isTenant = () => {
	let loginInfo = getStorage("loginInfo")
	// if (loginInfo && loginInfo.userType === "TENANT") {
	// 	return true
	// }else if(loginInfo && loginInfo.userType === "NOT_YET_TENANT"){
	// 	return false
	// }else if(loginInfo.token== undefined){ 
	// 	return false
	// }
	// else{
	// 	return true
	// }
	console.log(1111, loginInfo)
	// TENANT租户NOT_YET_TENANT不是租户Notloggedin未登录Admin管理员
	if (loginInfo && loginInfo.userType === "TENANT") {
		return 'TENANT'
	} else if (loginInfo && loginInfo.userType === "NOT_YET_TENANT") {
		return "NOT_YET_TENANT"
	} else if (loginInfo.token == undefined) {
		return 'Notloggedin'
	} else {
		return 'Admin'
	}

}

const getCacheData = (key) => {
	let loginInfo = getStorage("loginInfo");
	let cacheList = getStorage(loginInfo.customerId + key)
	return cacheList
}

const cacheData = (key, data) => {
	let loginInfo = getStorage("loginInfo");
	let cacheList = getStorage(loginInfo.customerId + key)
	if (!cacheList) {
		cacheList = []
	} else {
		for (let item of cacheList) {
			if (item["key"] === data["key"]) {
				cacheList.splice(item, 1)
				break
			}
		}
	}
	data["key"] = getNowDate()
	cacheList.push(data)
	setStorage(loginInfo.customerId + key, cacheList)
	console.warn("数据缓存成功: ", cacheList)
	return data
}
const removeCacheData = (key, data) => {
	let loginInfo = getStorage("loginInfo");
	let cacheList = getStorage(loginInfo.customerId + key)
	if (cacheList) {
		for (let item of cacheList) {
			if (item["key"] === data["key"]) {
				cacheList.splice(item, 1)
				break
			}
		}
	}
	setStorage(loginInfo.customerId + key, cacheList)
	console.warn("删除缓存数据成功: ", cacheList)
}

const changeMenuTwo = (key, data) => {
	uni.setTabBarItem({
		index: 2,
		text: "我的",
		success: function(res) {}
	})
	// {
	// 	"pagePath": "pages/message/message",
	// 	"iconPath": "static/house.png",
	// 	"selectedIconPath": "static/house-a.png",
	// 	"text": "消息"
	// },
	if (isTenant() == 'Admin') {
		uni.setTabBarItem({
			index: 1,
			// pagePath: "pages/message/message",
			iconPath: "static/mine.png",
			selectedIconPath: "static/mine-a.png",
			text: "消息",
			success: function(res) {}
		})
	} else {
		uni.setTabBarItem({
			index: 1,
			text: "物业信息",
			success: function(res) {}
		})
	}
}
/**
 * 预览文件
 * @param {string} fileUrl 文件路径
 */
const openFile = (fileUrl) => {
	uni.downloadFile({
		url: fileUrl,
		success: (res) => {
			if (res.statusCode === 200) {
				uni.openDocument({
					filePath: res.tempFilePath,
					// 如果文件名包含中文，建议使用escape(res.tempFilePath)转码，防止ios和安卓客户端导致的差异
					success: function(res) {
						console.log('打开文档成功');
					},
					fail: function(err) {
						console.log(err)
					},
					complete(res) {
						console.log(res)
					},
				});
			}
		}
	});
}
/**
 *数组对象的排序
 *
 * @param {Array} compareArr 排序数组对象
 * @param {string} property 跟数组里面某个对象排序
 * @param {boolean} desc 是否降序
 * @returns {Array}
 * @example let arr = [
 * {id:2},
 * {id:7},
 * {id:3},
 * {id:11}
 * ];
 * 		compare(arr,'id',false) // [{id:2},{id:3},{id:7},{id:11}]
 * 		compare(arr,'id',true) // [{id:11},{id:7},{id:3},{id:2}]
 */
const compare = (compareArr, property, desc) => {
	let sortType = '';
	if (desc) {
		sortType = function(a, b) {
			let val1 = a[property]
			let val2 = b[property]
			return val2 - val1
		}
	} else {
		sortType = function(a, b) {
			let val1 = a[property]
			let val2 = b[property]
			return val1 - val2
		}
	}
	return compareArr.sort(sortType)

}

const contains = (array, value, key) => {
	if (array) {
		for (let item of array) {
			if (item[key] === value[key]) {
				return true
			}
		}
	}
	return false
}

const phoneCall = (number) => {
	uni.makePhoneCall({
		phoneNumber: number //仅为示例
	});
}

const openLocation = (lat = 24.297485, lon = 113.404328) => { // 默认位置为“广州市黄埔区开达路101号科学城集团总部大楼”
	uni.openLocation({
		latitude: lat,
		longitude: lon,
		scale: 18
	})
}

const addShoppingCart = (info) => {
	let cartList = getStorage("shopping_cart" + getStorage('loginInfo').account)
	if (!cartList) cartList = []

	for (let item of cartList) {
		if (item.property_id === info.property_id) {
			return;
		}
	}
	cartList.push(info)
	setStorage("shopping_cart" + getStorage('loginInfo').account, cartList)

	console.warn("加入购物车：", cartList)
}

const getShoppingCart = () => {
	let cartList = getStorage("shopping_cart" + getStorage('loginInfo').account)
	if (!cartList) cartList = []

	console.warn("获取购物车列表：", cartList)
	return cartList;
}

const removeShoppingCart = (ids = [], keyName = "property_id") => {
	let cartList = getStorage("shopping_cart" + getStorage('loginInfo').account)
	if (!cartList) cartList = []

	let cartListTemp = [];
	for (let item of cartList) {
		console.warn("property_id: ", item[keyName])
		if (ids.indexOf(item[keyName]) < 0) {
			cartListTemp.push(item)
		}
	}
	setStorage("shopping_cart" + getStorage('loginInfo').account, cartListTemp)
}

const checkIsInShoppingCart = (id, keyName = "property_id") => {
	let cartList = getStorage("shopping_cart" + getStorage('loginInfo').account)
	if (!cartList) cartList = []

	// console.warn("购物车列表：", cartList)
	for (let item of cartList) {
		if (item[keyName] === id) {
			return true;
		}
	}
	return false
}

const isIdcard = (str) => {
	const re15 = /^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$/;
	const re18 = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
	return re15.test(str) || re18.test(str);
}

//上传图片
const fileNames = [];
const uploadFilePromise = (urlTemp) => {
	return new Promise((resolve, reject) => {
		console.log("kkkk", getStorage("loginInfo"))
		let loginInfo = getStorage("loginInfo")
		let url = config.BASE_URL + "app/mySelf/uploadPicfile?token=" + loginInfo.token
		console.warn("url: ", url)
		let header = {}
		// #ifndef H5
		header = {
			"Content-Type": "multipart/form-data"
		};
		// #endif
		let a = uni.uploadFile({
			url: url, // 后端api接口
			filePath: urlTemp, // uni.chooseImage函数调用后获取的本地文件路劲
			name: 'file', //后端通过'file'获取上传的文件对象
			// formData: {
			// 	user: 'test'
			// },
			header: header,
			success: (res) => {
				// setTimeout(() => {
				// 	resolve(res.data.data)
				// }, 1000)
				if (res.data) {
					res = JSON.parse(res.data);
					if (res.result) {
						fileNames.push(res.result)
						console.log("res:", res)
						// imageUrls.concat([formatImgPath(res.result+";")])
					}
				}
				resolve(res);
			}
		});
	})
}

/**
 * deviceType
 * 	1：PAD门禁
 * 	2：停车场门禁
 * 	3：空调
 * 	4-1：灌溉-开
 *  4-2：灌溉-关
 * 	5：照明
 */
const ctrlUrl = 'http://192.168.1.114:8089'
const deviceCtrl = (url, id) => {
	return post({
		url: ctrlUrl + url,
		data: {
			serial_id: id
		}
	}, 1)
}

//获取轮播图
const getPictureSwith = (url) => {
	return post({
		url: url
	})
}

module.exports = {
	getPictureSwith,
	uploadFilePromise,
	getNowDate,
	getDate,
	isBefore,
	isAfter,
	getSystemInfo,
	formatVersion,
	previewImage,
	setStorage,
	getStorage,
	urlParams,
	getPhoto,
	getMedia,
	uploadFile,
	get,
	post,
	postGraphql,
	request,
	formatGraphqlQuery,
	toast,
	alert,
	confirm,
	showLoading,
	hideLoading,
	goHome,
	imageToBase64,
	getElementInfo,
	checkBind,
	getImageUrl,
	noOpen,
	getHeightWithTopEl,
	getElRect,
	reLaunchHomePage,
	loginSuccess,
	logout,
	getRights,
	isLogin,
	getCacheData,
	cacheData,
	removeCacheData,
	changeMenuTwo,
	isTenant,
	contains,
	openFile,
	compare,
	phoneCall,
	openLocation,
	addShoppingCart,
	getShoppingCart,
	checkIsInShoppingCart,
	removeShoppingCart,
	isIdcard,
	initFeedbackType,
	removeStorage,
	deviceCtrl,
};